package File;

import java.io.File;
import java.io.FileFilter;

public class ListFileDemo2 {
    public static void main(String[] args) {

        File dir=new File("./");

        File[] subs=dir.listFiles(file->file.getName().endsWith(".txt"));
        System.out.println(subs.length);
        for (File sub:subs)
        {
            System.out.println(sub.getName());
        }



/*
        if (dir.isDirectory()) {
            FileFilter filter=new FileFilter() {
                @Override
                public boolean accept(File file) {
                    String name=file.getName();
                    return name.endsWith(".txt");
                }
            };

            File[] subs=dir.listFiles(filter);
            System.out.println(subs.length);
            for (File sub:subs)
            {
                System.out.println(sub.getName());
            }


        }

 */
    }
}
